﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var toannhPopupStatus = 0;

//loading popup with jQuery magic!
function toannhPopup(){
	//loads popup only if it is disabled
	if(toannhPopupStatus==0){
		centerToannhPopup();
		$("#toannhPopupBackground").css({
			"opacity": "0.7","filter":"alpha(opacity=70)"
		});
		$("#toannhPopupBackground").fadeIn("fast");
		$("#toannhPopup").fadeIn("slow");
		toannhPopupStatus = 1;
		$('div.pu-box').pngFix( );
	}
}

//disabling popup with jQuery magic!
function disableToannhPopup(){
	//disables popup only if it is enabled
	if(toannhPopupStatus==1){
		$("#toannhPopupBackground").fadeOut();
		$("#toannhPopupBackground").hide();
		$("#toannhPopup").fadeOut();
		$("#toannhPopup").hide();
		toannhPopupStatus = 0;
		try {
			$('#fade').fadeOut();
		}
		catch (e){return true;}
	}
}

//centering popup
function centerToannhPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var bodywidth = $('body').innerWidth();
	var bodyheight = $('body').innerHeight();
	var popupHeight = $("#toannhPopup").height();
	var popupWidth = $("#toannhPopup").width();
	
	var wpos = (bodywidth > windowWidth) ? bodywidth : windowWidth;
	var hpos = (bodyheight > windowHeight) ? bodyheight : windowHeight;
	var scrollWindow = $(window).scrollTop();
	var top = windowHeight/2-((popupHeight/3)*2) + scrollWindow;
	var left = windowWidth/2-popupWidth/2;
	
	$("#toannhPopupBackground").css({
		"height": hpos,
		"width" : wpos
	});
	
	//centering
	$("#toannhPopup").css({
		"position": "absolute",
		"top": top,
		"left": left
	});
	//only need force for IE6
	
	$(window).scroll(function(){
		if($('#toannhPopup').css('display') != 'none')
		{
			$('#toannhPopup').stop();
			var scroll = $(window).scrollTop();
			var scrollPos = windowHeight/2-((popupHeight/3)*2) + scroll;
			$('#toannhPopup').animate({top: scrollPos},'slow');
		}
	});
}